package com.wms.controller;

import com.wms.bean.PageBean;
import com.wms.bean.ResultBean;
import com.wms.core.R;
import com.wms.dto.AddStkByGoodsDTO;
import com.wms.dto.CommodityDTO;
import com.wms.dto.ProductsDTO;
import com.wms.entity.TaskUser;
import com.wms.service.impl.AddStkByGoodsServiceImpl;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@Api(tags = "skh-添加盘点任务(按物品)")
public class AddStkByGoodsController {


    @Autowired
    AddStkByGoodsServiceImpl addStkByGoodsService;

    @PostMapping("/AddStkByGoods")
    @ApiOperation("添加盘点任务(按物品)")
    public ResultBean add(@RequestBody AddStkByGoodsDTO dto) {
        int rs = addStkByGoodsService.addStkByGoods(dto);
        if (rs > 0) {
            return R.success("添加成功");
        }
        return R.fail("添加失败");
    }

    @GetMapping("/queryUserByStoreId")
    @ApiOperation("根据仓库ID查询默认盘点人ID和盘点人姓名")
    public ResultBean queryUserByStoreId(@RequestParam(value = "storeId") int storeId) {
        TaskUser taskUser = addStkByGoodsService.queryUserByStoreId(storeId);
        if (taskUser != null) {
            return R.success("查询成功", taskUser);
        }
        return R.fail("查询失败");
    }

    @GetMapping("/queryProductsByStoreId")
    @ApiOperation("根据仓库ID查询该仓库下的产品信息（type=1）")
    public ResultBean<PageBean<ProductsDTO>> queryProductsByStoreId(@RequestParam(value = "storeId") int storeId, @RequestParam(value = "page") int page, @RequestParam(value = "pageSize") int pageSize) {
        PageBean pageBean = addStkByGoodsService.queryProductsByStoreId(storeId, page, pageSize);
        if (pageBean != null) {
            return R.success("查询成功", pageBean);
        }
        return R.fail("查询失败");
    }

    @GetMapping("/queryCommodityByStoreId")
    @ApiOperation("根据仓库ID查询该仓库下的商品信息（type=2）")
    public ResultBean<PageBean<CommodityDTO>> queryCommodityByStoreId(@RequestParam(value = "storeId") int storeId, @RequestParam(value = "page") int page, @RequestParam(value = "pageSize") int pageSize) {
        PageBean pageBean = addStkByGoodsService.queryCommodityByStoreId(storeId, page, pageSize);
        if (pageBean != null) {
            return R.success("查询成功", pageBean);
        }
        return R.fail("查询失败");
    }
}
